package com.javasm.gm;



import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.javasm.commons.entity.TableDatas;
import com.javasm.process.entity.ProcessTask;
import com.javasm.sys.CurrentLogin;
import com.javasm.sys.constant.Constants;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import com.javasm.commons.base.BaseController;
import com.javasm.commons.entity.AxiosResult;

@RestController
@RequestMapping("goods2Gifts")
public class Goods2GiftsController extends BaseController {
    @Resource
    private Goods2GiftsService baseService;

    @GetMapping("{id}")
    public AxiosResult getByIds(@PathVariable String id) {
        Goods2Gifts gg = baseService.getOneById(id);
        return suc(gg);
    }

    @GetMapping
    public AxiosResult getList(Goods2Gifts obj) {
        startPage();
        Collection<Goods2Gifts> list = baseService.listGoods2GiftsApply(obj);
        return suc(new TableDatas(list));
    }

    @PostMapping("cg")
    public AxiosResult insertCg(@RequestBody Goods2Gifts obj) {
        obj.setApplyStatus(Constants.CG);
        obj.setApplyUser(CurrentLogin.getLoginUserName());
        boolean b =false;
        if(StrUtil.isEmpty(obj.getId())){
            b = baseService.save(obj);
        }else{
            b=baseService.updateById(obj);
        }
        return isok(b);
    }

    @PostMapping("tj")
    public AxiosResult insertTj(@RequestBody Goods2Gifts obj) {
        obj.setApplyStatus(Constants.SHZ);
        obj.setApplyUser(CurrentLogin.getLoginUserName());
        boolean b =false;
        b=baseService.submitApply(obj);
        return isok(b);
    }

    @GetMapping("/audit/{orderId}")
    public AxiosResult getTasks(@PathVariable String orderId) {
        List<ProcessTask> tasks = baseService.getTaskByApplyOrderId(orderId);
        return suc(tasks);
    }

    @GetMapping("todos")
    public TableDatas getToDoTasks(){
        startPage();
        List<ProcessTask> tasks = baseService.queryToDoTasks();
        return toTableDatas(tasks);
    }

    //查询已办
    @GetMapping("dos")
    public TableDatas getdosWtgTasks(){
        startPage();
        List<ProcessTask> tasks = baseService.queryDosTasks(null);
        return toTableDatas(tasks);
    }

    @GetMapping("claim/{orderId}")
    public AxiosResult doClaim(@PathVariable String orderId){
        boolean f = baseService.claim(orderId);
        return isok(f);
    }

    //审批
    @PostMapping("doapprove")//做审批
    public AxiosResult doApprove(@RequestBody ProcessTask task){
        boolean b = baseService.approve(task);

        return isok(b);
    }

    @PutMapping
    public AxiosResult updateById(@RequestBody Goods2Gifts obj) {
        boolean b = baseService.updateById(obj);
        return isok(b);
    }

    @DeleteMapping("{ids}")
    public AxiosResult delByIds(@PathVariable String ids) {
        boolean b = baseService.removeByIds(Arrays.asList(ids.split(",")));
        return isok(b);
    }
}

